package cn.dlc.com.sort;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author 邓立川
 * @date 2021/3/12 21:47
 * @desc Comparable接口的使用
 */
public class Demo7 {

    public static void main(String[] args) {
        Student jack = new Student("jack", 12);
        Student rose = new Student("rose", 11);
        Comparable result = getMax(jack, rose);
        System.out.println(result);
    }

    private static Comparable getMax(Comparable c1,Comparable c2) {
        int result = c1.compareTo(c2);

        if(result > 0) {
            return c1;
        } else {
            return c2;
        }
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @ToString
    private static class Student implements Comparable<Student>{

        private String name;
        private int age;

        // 实现比较方法
        public int compareTo(Student o) {
            return this.getAge() - o.getAge();
        }
    }
}


